PACKAGE=vit
VERSION := $(shell rpm -q --qf '%{version}\n' --specfile $(PACKAGE).spec | head -1)
RELEASE := $(shell rpm -q --qf '%{release}\n' --specfile $(PACKAGE).spec | head -1)

TEXTDOMAIN   = ${PACKAGE}

RPM          = /usr/bin/rpm

PRODUCT      = "PCLinuxOS 2007"
export PRODUCT

MSGFMT       = /usr/bin/msgfmt


bindir=/usr/bin
sbindir=/usr/sbin
datadir=/usr/share
localedir=$(datadir)/locale


INSTLOCALES := ${patsubst l10n/%.po,%,${wildcard l10n/*.po}}
POS := ${wildcard l10n/*.po}
MOS := ${patsubst %.po,%.mo,${POS}}

.PHONY: all clean installdirs install cleandist distdir localcopy tar rpm rpm-install ${INSTLOCALES}

all: ${MOS} ${PACKAGE}.desktop

${PACKAGE}.desktop: ${PACKAGE}.desktop.in
	intltool-merge l10n/ -d -u -c l10n/.intltool-merge-cache $< $@

${MOS}: l10n/%.mo : l10n/%.po
	$(MSGFMT) -o $@ $<

installdirs:
	install -d -m 0755 $(prefix)/$(bindir)
	install -d -m 0755 $(prefix)/$(datadir)/license
	install -d -m 0755 $(prefix)/$(datadir)/mdk/backgrounds
	install -d -m 0755 $(prefix)/$(sbindir)
	install -d -m 0755 $(prefix)/$(datadir)/applications

${INSTLOCALES}: %: l10n/%.mo
	install -d -m 755 $(prefix)/$(localedir)/$@/LC_MESSAGES/
	install -m 644 $< $(prefix)/$(localedir)/$@/LC_MESSAGES/${TEXTDOMAIN}.mo

install: all installdirs ${INSTLOCALES}
	install -m 0755 vit $(prefix)/$(bindir)/vit
	install -m 0644 ati.html $(prefix)/$(datadir)/license/ati.html
	install -m 0644 nvidia.html $(prefix)/$(datadir)/license/nvidia.html
	install -m 0644 vit.jpg $(prefix)/$(datadir)/mdk/backgrounds/vit.jpg
	
	install -m 0755 install-ati-8x.sh $(prefix)/$(sbindir)/install-ati-8x.sh
	install -m 0755 install-ati.sh $(prefix)/$(sbindir)/install-ati.sh
	#install -m 0755 install-nvidia_100.14.xx.sh $(prefix)/$(sbindir)/install-nvidia_100.14.xx.sh
	install -m 0755 install-nvidia_169.xx.sh $(prefix)/$(sbindir)/install-nvidia_169.xx.sh
	install -m 0755 install-nvidia_71xx.sh $(prefix)/$(sbindir)/install-nvidia_71xx.sh
	install -m 0755 install-nvidia_96xx.sh $(prefix)/$(sbindir)/install-nvidia_96xx.sh
	#install -m 0755 install-nvidia_97xx.sh $(prefix)/$(sbindir)/install-nvidia_97xx.sh
		
	#xdg menu
	install -m 0644 $(PACKAGE).desktop $(prefix)/$(datadir)/applications/$(PACKAGE).desktop


clean:
	rm -f l10n/*.mo
	rm -f $(PACKAGE).desktop
	rm -f l10n/.intltool-merge-cache

cleandist:
	rm -rf $(PACKAGE)-$(ARCHIVEVER) $(PACKAGE)-$(VERSION).tar.bz2

distdir:
	if [ ! -d $(PACKAGE)-$(VERSION) ]; then mkdir $(PACKAGE)-$(VERSION); fi

localcopy: clean distdir
	tar cp --exclude=.svn --exclude=$(PACKAGE)-$(VERSION) --exclude=*.tar.bz2  . | tar xp -C $(PACKAGE)-$(VERSION)
	
tar: localcopy cleandist
	tar cjvf $(PACKAGE)-$(VERSION).tar.bz2 $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)

rpm: tar
	rpmbuild -ta $(PACKAGE)-$(VERSION).tar.bz2

rpm-install: rpm
	rpm -Uvh --force /usr/src/rpm/RPMS/noarch/$(PACKAGE)-$(VERSION)-$(RELEASE).noarch.rpm
